﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace d39
{
    [Serializable]
    public struct Vector
    {
        public Vector(int x, int y)
        {
            X = x;
            Y = y;
        }

        public readonly int X;
        public readonly int Y;

        public static readonly Vector Zero = default(Vector);

        public static readonly Vector N = new Vector(0, -1);
        public static readonly Vector NE = new Vector(1, -1);
        public static readonly Vector E = new Vector(1, 0);
        public static readonly Vector SE = new Vector(1, 1);
        public static readonly Vector S = new Vector(0, 1);
        public static readonly Vector SW = new Vector(-1, 1);
        public static readonly Vector W = new Vector(-1, 0);
        public static readonly Vector NW = new Vector(-1, -1);

        public static Vector Parse(string str, int start, out int end)
        {
            var x = Base26.ParseInt(str, start, out end);
            var y = Base26.ParseInt(str, end, out end);
            return new Vector(x, y);
        }

        public override string ToString()
        {
            return Base26.IntToString(X) + Base26.IntToString(Y);
        }
        public string ToHumanReadableString()
        {
            return "(" + X + "," + Y + ")";
        }

        public static Vector operator +(Vector a, Vector b)
        {
            return new Vector(a.X + b.X, a.Y + b.Y);
        }
        public static Vector operator -(Vector v)
        {
            return new Vector(-v.X, -v.Y);
        }
        public static Vector operator -(Vector a, Vector b)
        {
            return new Vector(a.X - b.X, a.Y - b.Y);
        }
        public static Vector operator *(Vector a, int n)
        {
            return new Vector(a.X * n, a.Y * n);
        }
        public static Vector operator *(int n, Vector a)
        {
            return new Vector(a.X * n, a.Y * n);
        }
        public static bool operator ==(Vector a, Vector b)
        {
            return a.X == b.X && a.Y == b.Y;
        }
        public static bool operator !=(Vector a, Vector b)
        {
            return a.X != b.X || a.Y != b.Y;
        }
        public override bool Equals(object obj)
        {
            return obj is Vector && this == ((Vector)obj);
        }
        public override int GetHashCode()
        {
            return X.GetHashCode() ^ Y.GetHashCode();
        }
    }
}